package com.magic.smartcity.model;

import com.magic.smartcity.interfaces.ISystemServicesModel;
import com.magic.smartcity.model.network.SystemService;
import com.magic.smartcity.presenters.SystemServicePresenter;

import org.greenrobot.eventbus.EventBus;

import javax.inject.Inject;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.schedulers.Schedulers;
import retrofit2.Retrofit;

/**
 * @description:
 * @create: Create by Magic on 2022/2/9.
 */
public class SystemServicesModel implements ISystemServicesModel {
    private static final String TAG = SystemServicesModel.class.getSimpleName();
    @Inject
    Retrofit mRetrofit;

    @Inject
    SystemServicesModel() {
    }

    ;

    @Override
    public void getAllService() {
        SystemService allService = mRetrofit.create(SystemService.class);
        allService.getServicesList()
                .observeOn(Schedulers.io())
                .subscribeOn(AndroidSchedulers.mainThread())
                .doOnError(throwable -> {
                    throwable.printStackTrace();
                })
                .subscribe(serviceListBean -> {
                    SystemServicePresenter.EventBusMessage message = new SystemServicePresenter.EventBusMessage();
                    if (serviceListBean.getCode() == 200) {
                        message.sellServices(serviceListBean.getRows());
                        EventBus.getDefault().post(message);//返送数据结果
                    }
                });
    }
}
